package com.hubt.controller;

import java.util.UUID;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hubt.common.PageBean;
import com.hubt.model.PtRRoleOrgan;
import com.hubt.model.PtUser;
import com.hubt.service.PtUserService;
import com.hubt.vo.Dutyvo;
import com.hubt.vo.UserDuty;
import com.hubt.vo.Uservo;

@RequestMapping("/user")
@Controller
public class PtUserController {
	@Autowired PtUserService ptUserService;

	
	
	@RequestMapping(value = "/getUsers",method = RequestMethod.GET)
	@ResponseBody
	public PageBean<Uservo> fianBean(@Param("pageSize") Integer pageSize,@Param("pagaNumber") Integer pageNumber){
		System.out.println(pageNumber+","+pageSize);
		PageBean<Uservo> pageBean=new PageBean<Uservo>();
		pageBean=ptUserService.findByPage(pageNumber, pageSize);
		System.out.println(pageBean);
		return pageBean;
	}
	
	@RequestMapping("/getUser")
    @ResponseBody
    public PtUser getOneUser(@Param("uuid") String uuid) {
    	return ptUserService.getUserById(uuid);
    }
	
    
    @RequestMapping(value="/update",method=RequestMethod.POST)
    @ResponseBody
    public Integer updateUsers(@Param("form") UserDuty uservo) {
    	ptUserService.updateUser(uservo);
    	return 1;
    }
	
    
    @RequestMapping("/insert")
    @ResponseBody
    public Integer insertUsers(@Param("form") UserDuty uservo) {
    	
    	uservo.setUser_uuid(UUID.randomUUID().toString());
//    	for(Dutyvo t:uservo.getDuties()) {
//    		System.out.println(t.getDutyId());
//    	}
//    	System.out.println(uservo.getDuties());
    	ptUserService.addUser(uservo);
    	return 1;
    }
	
    
    @RequestMapping("/remove")
    @ResponseBody
    public Integer deleteUsers(@Param("id") String id) {
    	ptUserService.deleteUser(id);
    	return 1;
}
	
	
}
